package guiLayer;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.JTabbedPane;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JTextField;
import javax.swing.JComboBox;

import modelLayer.Person;
import controllerLayer.StatusController;

import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

public class ProEmpGUI extends JFrame {

	
	private StatusController sCtr = new StatusController();
	
	private JPanel contentPane;
	private JPanel panel;
	
	
	

		
	

	private JLabel lblFornavn;
	private JLabel lblEfternavn;
	private JLabel lblAdresse;
	private JTextField textField_fName;
	private JTextField textField_lName;
	private JTextField textField_city;
	private JLabel lblAdresse_1;
	private JTextField textField_Address;
	private JLabel lblTelefon;
	private JLabel lblMobil;
	private JTextField textField_4;
	private JTextField textField_5;
	private JLabel lblKontaktperson;
	private JLabel lblTelefon_1;
	private JLabel lblMobil_1;
	private JTextField textField_contactPerson;
	private JTextField textField_phoneNo;
	private JTextField textField_mobile;
	
	//required fields
	private JLabel lblrequiredFname;
	private JLabel lblrequiredLname;
	private JLabel lblrequiredPostCode;
	private JLabel lblrequiredAddress;
	private JLabel lblrequiredPhone;
	private JLabel lblrequiredMobile;
	private JLabel lblrequiredInitial;
	
	
	
	private JComboBox<String> comboBox_postCode;
	private JLabel lblInitial;
	private JTextField textField_9;
	private JPanel panel_table = new JPanel();
	
	
	private String pid = "id";
	private String fName = "fornavn";
	private String lName = "efternavn";
	private String address = "adresse";
	private String postCode = "post nr.";
	private String phone = "telefon";
	private String mobile = "mobil";
	private String contactPerson = "kontakt Person";
	private String contactPhone = "k telefon";
	private String contactMobile = "k mobil";
	private String initial = "initial";
	
	private String[] columnsNames = {pid, initial, fName, lName, address, postCode, phone, mobile, contactPerson, contactPhone, contactMobile};
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ProEmpGUI frame = new ProEmpGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
		
	public ProEmpGUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1024, 679);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);		
		
		
		
		makePanel();
		makePanel1();
		makeJTable();
	}
	
	public JPanel makeAll(){
		makePanel();
		makePanel1();
		makeJTable();
		
		return contentPane;
	}
	
	
	private void makePanel(){
		
		
//		panel = new JPanel();
//		panel.setLayout(null);
//		contentPane.add(panel, BorderLayout.CENTER);
		
		panel = new JPanel();
		panel.setPreferredSize(new Dimension(1024, 700));
		panel.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane(panel);
		
		contentPane.add(scrollPane, BorderLayout.CENTER);
		
	}
	
	private void makePanel1(){
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(10, 11, 738, 207);
		panel.add(panel_1);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
		gbl_panel_1.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel_1.setLayout(gbl_panel_1);
		{
			lblFornavn = new JLabel("fornavn");
			GridBagConstraints gbc_lblFornavn = new GridBagConstraints();
			gbc_lblFornavn.anchor = GridBagConstraints.EAST;
			gbc_lblFornavn.insets = new Insets(0, 0, 5, 5);
			gbc_lblFornavn.gridx = 0;
			gbc_lblFornavn.gridy = 0;
			panel_1.add(lblFornavn, gbc_lblFornavn);
		}
		
		textField_fName = new JTextField();
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 1;
		gbc_textField.gridy = 0;
		panel_1.add(textField_fName, gbc_textField);
		textField_fName.setColumns(15);
		{
			lblrequiredFname = new JLabel("fname");
			lblrequiredFname.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredFname.setForeground(Color.red);
			lblrequiredFname.setVisible(false);
			GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
			gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
			gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
			gbc_lblNewLabel.gridx = 2;
			gbc_lblNewLabel.gridy = 0;
			panel_1.add(lblrequiredFname, gbc_lblNewLabel);
		}
		{
			lblKontaktperson = new JLabel("kontaktPerson");
			GridBagConstraints gbc_lblKontaktperson = new GridBagConstraints();
			gbc_lblKontaktperson.anchor = GridBagConstraints.EAST;
			gbc_lblKontaktperson.insets = new Insets(0, 0, 5, 5);
			gbc_lblKontaktperson.gridx = 6;
			gbc_lblKontaktperson.gridy = 0;
			panel_1.add(lblKontaktperson, gbc_lblKontaktperson);
		}
		{
			textField_contactPerson = new JTextField();
			GridBagConstraints gbc_textField_6 = new GridBagConstraints();
			gbc_textField_6.insets = new Insets(0, 0, 5, 0);
			gbc_textField_6.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_6.gridx = 7;
			gbc_textField_6.gridy = 0;
			panel_1.add(textField_contactPerson, gbc_textField_6);
			textField_contactPerson.setColumns(10);
		}
		{
			lblEfternavn = new JLabel("efternavn");
			GridBagConstraints gbc_lblEfternavn = new GridBagConstraints();
			gbc_lblEfternavn.insets = new Insets(0, 0, 5, 5);
			gbc_lblEfternavn.anchor = GridBagConstraints.EAST;
			gbc_lblEfternavn.gridx = 0;
			gbc_lblEfternavn.gridy = 1;
			panel_1.add(lblEfternavn, gbc_lblEfternavn);
		}
		
		textField_lName = new JTextField();
		GridBagConstraints gbc_textField_1 = new GridBagConstraints();
		gbc_textField_1.insets = new Insets(0, 0, 5, 5);
		gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_1.gridx = 1;
		gbc_textField_1.gridy = 1;
		panel_1.add(textField_lName, gbc_textField_1);
		textField_lName.setColumns(10);
		{
			lblrequiredLname = new JLabel("lname");
			lblrequiredLname.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredLname.setForeground(Color.red);
			lblrequiredLname.setVisible(false);
			GridBagConstraints gbc_lblLname = new GridBagConstraints();
			gbc_lblLname.anchor = GridBagConstraints.WEST;
			gbc_lblLname.insets = new Insets(0, 0, 5, 5);
			gbc_lblLname.gridx = 2;
			gbc_lblLname.gridy = 1;
			panel_1.add(lblrequiredLname, gbc_lblLname);
		}
		{
			lblTelefon_1 = new JLabel("telefon");
			GridBagConstraints gbc_lblTelefon_1 = new GridBagConstraints();
			gbc_lblTelefon_1.anchor = GridBagConstraints.EAST;
			gbc_lblTelefon_1.insets = new Insets(0, 0, 5, 5);
			gbc_lblTelefon_1.gridx = 6;
			gbc_lblTelefon_1.gridy = 1;
			panel_1.add(lblTelefon_1, gbc_lblTelefon_1);
		}
		{
			textField_phoneNo = new JTextField();
			GridBagConstraints gbc_textField_7 = new GridBagConstraints();
			gbc_textField_7.insets = new Insets(0, 0, 5, 0);
			gbc_textField_7.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_7.gridx = 7;
			gbc_textField_7.gridy = 1;
			panel_1.add(textField_phoneNo, gbc_textField_7);
			textField_phoneNo.setColumns(10);
		}
		{
			lblAdresse = new JLabel("by");
			GridBagConstraints gbc_lblAdresse = new GridBagConstraints();
			gbc_lblAdresse.anchor = GridBagConstraints.EAST;
			gbc_lblAdresse.insets = new Insets(0, 0, 5, 5);
			gbc_lblAdresse.gridx = 0;
			gbc_lblAdresse.gridy = 2;
			panel_1.add(lblAdresse, gbc_lblAdresse);
		}
		
		comboBox_postCode = new JComboBox<String>();
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 1;
		gbc_comboBox.gridy = 2;
		panel_1.add(comboBox_postCode, gbc_comboBox);
		
		textField_city = new JTextField();
		GridBagConstraints gbc_textField_2 = new GridBagConstraints();
		gbc_textField_2.insets = new Insets(0, 0, 5, 5);
		gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_2.gridx = 2;
		gbc_textField_2.gridy = 2;
		panel_1.add(textField_city, gbc_textField_2);
		textField_city.setColumns(10);
		{
			lblrequiredPostCode = new JLabel("postCode");
			lblrequiredPostCode.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredPostCode.setForeground(Color.red);
			lblrequiredPostCode.setVisible(false);
			GridBagConstraints gbc_lblAddress = new GridBagConstraints();
			gbc_lblAddress.insets = new Insets(0, 0, 5, 5);
			gbc_lblAddress.gridx = 3;
			gbc_lblAddress.gridy = 2;
			panel_1.add(lblrequiredPostCode, gbc_lblAddress);
		}
		{
			lblMobil_1 = new JLabel("mobil");
			GridBagConstraints gbc_lblMobil_1 = new GridBagConstraints();
			gbc_lblMobil_1.anchor = GridBagConstraints.EAST;
			gbc_lblMobil_1.insets = new Insets(0, 0, 5, 5);
			gbc_lblMobil_1.gridx = 6;
			gbc_lblMobil_1.gridy = 2;
			panel_1.add(lblMobil_1, gbc_lblMobil_1);
		}
		{
			textField_mobile = new JTextField();
			GridBagConstraints gbc_textField_8 = new GridBagConstraints();
			gbc_textField_8.insets = new Insets(0, 0, 5, 0);
			gbc_textField_8.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_8.gridx = 7;
			gbc_textField_8.gridy = 2;
			panel_1.add(textField_mobile, gbc_textField_8);
			textField_mobile.setColumns(10);
		}
		{
			lblAdresse_1 = new JLabel("adresse");
			GridBagConstraints gbc_lblAdresse_1 = new GridBagConstraints();
			gbc_lblAdresse_1.anchor = GridBagConstraints.EAST;
			gbc_lblAdresse_1.insets = new Insets(0, 0, 5, 5);
			gbc_lblAdresse_1.gridx = 0;
			gbc_lblAdresse_1.gridy = 3;
			panel_1.add(lblAdresse_1, gbc_lblAdresse_1);
		}
		{
			textField_Address = new JTextField();
			GridBagConstraints gbc_textField_3 = new GridBagConstraints();
			gbc_textField_3.insets = new Insets(0, 0, 5, 5);
			gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_3.gridx = 1;
			gbc_textField_3.gridy = 3;
			panel_1.add(textField_Address, gbc_textField_3);
			textField_Address.setColumns(10);
		}
		{
			lblrequiredAddress = new JLabel("address");
			lblrequiredAddress.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredAddress.setForeground(Color.red);
			lblrequiredAddress.setVisible(false);
			GridBagConstraints gbc_lblAddress_1 = new GridBagConstraints();
			gbc_lblAddress_1.anchor = GridBagConstraints.WEST;
			gbc_lblAddress_1.insets = new Insets(0, 0, 5, 5);
			gbc_lblAddress_1.gridx = 2;
			gbc_lblAddress_1.gridy = 3;
			panel_1.add(lblrequiredAddress, gbc_lblAddress_1);
		}
		{
			lblTelefon = new JLabel("telefon");
			GridBagConstraints gbc_lblTelefon = new GridBagConstraints();
			gbc_lblTelefon.anchor = GridBagConstraints.EAST;
			gbc_lblTelefon.insets = new Insets(0, 0, 5, 5);
			gbc_lblTelefon.gridx = 0;
			gbc_lblTelefon.gridy = 4;
			panel_1.add(lblTelefon, gbc_lblTelefon);
		}
		{
			textField_4 = new JTextField();
			GridBagConstraints gbc_textField_4 = new GridBagConstraints();
			gbc_textField_4.insets = new Insets(0, 0, 5, 5);
			gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_4.gridx = 1;
			gbc_textField_4.gridy = 4;
			panel_1.add(textField_4, gbc_textField_4);
			textField_4.setColumns(10);
		}
		{
			lblrequiredPhone = new JLabel("phone");
			lblrequiredPhone.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredPhone.setForeground(Color.red);
			lblrequiredPhone.setVisible(false);
			GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
			gbc_lblNewLabel_1.anchor = GridBagConstraints.WEST;
			gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
			gbc_lblNewLabel_1.gridx = 2;
			gbc_lblNewLabel_1.gridy = 4;
			panel_1.add(lblrequiredPhone, gbc_lblNewLabel_1);
		}
		{
			lblMobil = new JLabel("mobil");
			GridBagConstraints gbc_lblMobil = new GridBagConstraints();
			gbc_lblMobil.anchor = GridBagConstraints.EAST;
			gbc_lblMobil.insets = new Insets(0, 0, 5, 5);
			gbc_lblMobil.gridx = 0;
			gbc_lblMobil.gridy = 5;
			panel_1.add(lblMobil, gbc_lblMobil);
		}
		{
			textField_5 = new JTextField();
			textField_5.setColumns(10);
			GridBagConstraints gbc_textField_5 = new GridBagConstraints();
			gbc_textField_5.insets = new Insets(0, 0, 5, 5);
			gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_5.gridx = 1;
			gbc_textField_5.gridy = 5;
			panel_1.add(textField_5, gbc_textField_5);
		}
		{
			lblrequiredMobile = new JLabel("mobile");
			lblrequiredMobile.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredMobile.setForeground(Color.red);
			lblrequiredMobile.setVisible(false);
			GridBagConstraints gbc_lblMobile = new GridBagConstraints();
			gbc_lblMobile.anchor = GridBagConstraints.WEST;
			gbc_lblMobile.insets = new Insets(0, 0, 5, 5);
			gbc_lblMobile.gridx = 2;
			gbc_lblMobile.gridy = 5;
			panel_1.add(lblrequiredMobile, gbc_lblMobile);
		}
		{
			lblInitial = new JLabel("initial");
			GridBagConstraints gbc_lblInitial = new GridBagConstraints();
			gbc_lblInitial.anchor = GridBagConstraints.EAST;
			gbc_lblInitial.insets = new Insets(0, 0, 0, 5);
			gbc_lblInitial.gridx = 0;
			gbc_lblInitial.gridy = 6;
			panel_1.add(lblInitial, gbc_lblInitial);
		}
		{
			textField_9 = new JTextField();
			GridBagConstraints gbc_textField_9 = new GridBagConstraints();
			gbc_textField_9.insets = new Insets(0, 0, 0, 5);
			gbc_textField_9.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_9.gridx = 1;
			gbc_textField_9.gridy = 6;
			panel_1.add(textField_9, gbc_textField_9);
			textField_9.setColumns(10);
		}
		{
			lblrequiredInitial = new JLabel("ini");
			lblrequiredInitial.setFont(new Font("Tahoma", Font.PLAIN, 9));
			lblrequiredInitial.setForeground(Color.red);
			lblrequiredInitial.setVisible(false);
			GridBagConstraints gbc_lblIni = new GridBagConstraints();
			gbc_lblIni.anchor = GridBagConstraints.WEST;
			gbc_lblIni.insets = new Insets(0, 0, 0, 5);
			gbc_lblIni.gridx = 2;
			gbc_lblIni.gridy = 6;
			panel_1.add(lblrequiredInitial, gbc_lblIni);
		}
	
		
		
	}
	
	private void makeJTable(){
		
		
		
		panel_table.removeAll();
		panel_table.setBounds(10, 238, 923, 381);
		
		
		
		final List<Object[]> values = new ArrayList<Object[]>();
		
		 
		
		List<Person> list_person = sCtr.getAllPersonByType("ProductionEmployee", true);
		for(Person p : list_person){		
			
			values.add(new String[] {String.valueOf(p.getId()), p.getInitial(), p.getFname(), p.getLname(), p.getAddress(), p.getPostalCode(), p.getPhoneNo(),
					p.getMobileNo(), p.getContactPerson(), p.getContactPhone() , p.getContactMobile()});
			
			p(p.getId()+ p.getFname()+ p.getLname()+ p.getAddress()+ p.getPostalCode()+ p.getPhoneNo()+
					p.getMobileNo()+ p.getContactPerson()+ p.getContactMobile());
		}
		
		table  = new JTable(values.toArray(new Object[][] {}), columnsNames);
		table.setPreferredScrollableViewportSize(new Dimension(900, 300));
		table.setFillsViewportHeight(true);
		
		JScrollPane scrollPane = new JScrollPane(table);
		scrollPane.setBounds(0, 0, 1024, 300);
		
		panel_table.add(scrollPane);
		panel.add(panel_table);
		
		panel_table.revalidate();
		panel_table.repaint();
	}
	
	
	public void p(String e){System.out.println(e);}
}
